import re
import sys

DEFINE = re.compile(r'#define _gvmt_opcode_interpreter_(\w+) (\d+)')

f = open(sys.argv[1])
out = open(sys.argv[2], 'w')
print  >> out, 'package parser;'
print  >> out, 'public class Opcodes {'
names = { 0 : 'null' }

for line in f:
    match = DEFINE.search(line)
    if match:
        print >> out, 'public static final int %s = %s;' % (match.group(1).upper(), match.group(2))
        names[int(match.group(2))] = match.group(1)

print  >> out, 'public static final String[] names = {'
for i in range(len(names)):
    if i in names:
        print  >> out, '"%s",' % names[i]
    else:
        print "",
        
print  >> out, '};'
print  >> out, '}'
f.close()
out.close()


